home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
dte5_1.zip
/
HWSYSV.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-06
|
44KB
|
1,516 lines
/*
* Written by Douglas Thomson (1989/1990)
* Modified for pure System V release 2 by Jay Maynard (1990)
*
* This source code is released into the public domain.
*/
/*
* Name: dte - Doug's Text Editor program - hardware dependent module
* Purpose: This file contains all the code that needs to be different on
* different hardware.
* File: hwsysv.c
* Authors: Douglas Thomson and Jay Maynard
* System: This particular version is for generic System V release 2,
* although it should suit most versions of UNIX system V.
* Date: 28 November 1990
* Notes: This module has been kept as small as possible, to facilitate
* porting between different systems.
*/
#include <curses.h> /* used to access terminfo database */
#include <term.h> /* used to set terminal modes */
#include <fcntl.h> /* used to set up stdin with no delay reads */
#include <signal.h> /* used to trap various signals (future?) */
#include <varargs.h> /* used to pass a variable no. of arguments */
#include "common.h" /* dte types */
#include "hwdep.h" /* prototypes for functions here */
#include "utils.h" /* prototypes for display/input etc */
#include "version.h" /* current version number */
/*
* A bug in some versions of elm causes editing sessions not to be killed
* when elm is killed (for example when a modem user unplugs the 'phone
* while editing mail!).
* The editor process is inherited by the init process, so all I do here
* is have the editor commit suicide if it detects that its parent has
* died.
*/
#define ELM_BUG
/*
* prototypes for all functions in this file
*/
void error ARGS((int kind, ...));
static void myputchar ARGS((char c));
static void hw_attr ARGS((char attr));
static void att_check ARGS((void));
void att_stuff ARGS((void));
void hw_xygoto ARGS((void));
int hw_clreol ARGS((void));
int hw_linedel ARGS((int line));
int hw_lineins ARGS((int line));
int hw_backspace ARGS((void));
int hw_c_insert ARGS((void));
int hw_c_delete ARGS((void));
void hw_c_output ARGS((int c));
void hw_terminate ARGS((void));
static void process_input ARGS((void));
void hw_initialize ARGS((void));
int hw_c_avail ARGS((void));
int hw_c_input ARGS((void));
void main ARGS((int argc, char *argv[]));
void hw_move ARGS((text_ptr dest, text_ptr source, long number));
int hw_rename ARGS((char *old, char *new));
int hw_scroll_up ARGS((int top, int bottom));
int hw_scroll_down ARGS((int top, int bottom));
int min ARGS((int a, int b));
int hw_fattrib ARGS((char *name));
int hw_set_fattrib ARGS((char *name, int attrib));
int hw_unlink ARGS((char *name));
int hw_printable ARGS((int c));
int hw_load ARGS((char *name, text_ptr start, text_ptr limit, text_ptr *end));
static int write_file ARGS((char *name, char *mode, text_ptr start,
text_ptr end));
int hw_save ARGS((char *name, text_ptr start, text_ptr end));
int hw_append ARGS((char *name, text_ptr start, text_ptr end));
int hw_print ARGS((text_ptr start, text_ptr end));
void hw_copy_path ARGS((char *old, char *name, char *new));
#define REVERSE 1 /* reverse video (or standout) attribute */
#define HIGH 2 /* high intensity (or underline) attribute */
#define NORMAL 3 /* normal video attribute */
#define UNKNOWN 7 /* flag not yet set to TRUE or FALSE */
char *malloc(/*!void*/); /* memory allocator - this keeps lint happy */
/*
* the following variable determines the size of the memory buffer used. It
* is set to something reasonable in main.
*/
static int g_space = 0;
/*
* Name: error
* Purpose: To report an error, and usually make the user type <ESC> before
* continuing.
* Date: October 10, 1989
* Passed: kind: an indication of how serious the error was:
* TEMP: merely a message, do not wait for <ESC>
* DIAG: merely a message, but make sure user sees it
* WARNING: error, but editor can continue after <ESC>
* FATAL: abort the editor!
* format: printf format string for any arguments that follow
* ...: arguments to be printed
* Notes: This function should be system independent; that is the whole
* point of the "varargs" philosophy. However, two of the systems
* I have used implemented "varargs" incompatibly, and some older
* systems may not support the "varargs" macros at all...
*/
void error(kind, va_alist)
int kind;
va_dcl
{
char *format; /* printf format string for error message */
va_list argptr; /* used to access various arguments */
char buff[MAX_COLS]; /* somewhere to store error before printing */
int c; /* character entered by user to continue */
/*
* obtain the first two arguments
*/
va_start(argptr);
format = va_arg(argptr, char *);
/*
* tell the user what kind of an error it is
*/
switch (kind) {
case FATAL:
strcpy(buff, "Fatal error: ");
break;
case WARNING:
strcpy(buff, "Warning: ");
break;
case DIAG:
case TEMP:
strcpy(buff, "");
break;
}
/*
* prepare the error message itself
*/
vsprintf(buff + strlen(buff), format, argptr);
va_end(argptr);
/*
* tell the user how to continue editing if necessary
*/
if (kind == WARNING || kind == DIAG) {
strcat(buff, ": type <ESC>");
}
/*
* output the error message
*/
set_prompt(buff, 1);
if (kind == FATAL) {
/*
* no point in making the user type <ESC>, since the program is
* about to abort anyway...
*/
terminate();
exit(1);
}
else if (kind != TEMP) {
/*
* If necessary, force the user to acknowledge the error by
* typing <ESC> (or ^U).
* This prevents any extra commands the user has entered from
* causing problems after an error may have made them inappropriate.
*/
while ((c=c_input()) != 27 && c != CONTROL('U')) {
set_prompt(buff, 1);
}
}
}
/*
* Name: myputchar
* Purpose: To output one character to the display terminal.
* Date: October 10, 1989
* Passed: c: character to be displayed
* Notes: This function makes the write system call directly, to try to
* minimize the amount of buffering that takes place. (Since this
* editor tries to respond quickly to new commands, we do not
* want a whole screenful of output stored in a buffer waiting
* to be sent to the terminal!)
* For very high speed terminals, it may be more appropriate to
* encourage buffering... writing just one character has the
* disadvantage that under heavy load screen update sometimes
* "freezes" temporarily while other processes run!
*/
static void myputchar(c)
char c;
{
putc(c, stdout);
/* write(1, &c, 1); */
}
/*
* Name: hw_attr
* Purpose: To select a new attribute on the terminal.
* Date: October 10, 1989
* Passed: attr: the desired attribute
*/
static void hw_attr(attr)
char attr;
{
static int old_att = -1; /* existing attribute */
/*
* If there has been no change, then ignore the call (actually this
* should never happen, since hw_attr is only called when the
* attribute HAS changed...
*/
if (old_att == attr) {
return;
}
/*
* If we want the normal attribute, then there may be an easy way of
* getting it without undoing other attributes.
*/
if (attr == g_display.normal) {
if (exit_attribute_mode) {
tputs(exit_attribute_mode, 1, myputchar);
old_att = attr;
return;
}
}
/*
* end the current attribute
*/
if (old_att != g_disp